import React, { useEffect } from 'react'
import Header from '@/components/Header'
import style from './index.module.scss'
import { useNavigate, Outlet, useLocation } from 'react-router-dom'
import Menu from '@/components/Menu'
import _ from 'lodash'
export default function Index() {
  const navigate = useNavigate()
  const location = useLocation();
  useEffect(() => {
    const Info = localStorage.getItem('userInfo')
    Info ? navigate('/explor'): navigate('/login')
  },[])
    // 在页面加载时，检查并恢复之前的路由
    useEffect(() => {
      const savedRoute = localStorage.getItem('path');
      if (savedRoute) {
        // 如果有保存的路由，并且当前路径不是保存的路径，则跳转
        navigate(savedRoute);
      }
    }, []);
    // 更换路由时
    useEffect(() => {
      localStorage.setItem('path',location.pathname)
    }, [location.pathname]); 
  return (
    <>
      <div className={style.bigHome}>
        <Header></Header>
        <div className={style.Index}>
          <div className={style.Bottom}>
            <div className={style.Left}>
              <Menu />
            </div>
            <div className={style.Right}>
              <Outlet />
            </div>
          </div>
        </div>
      </div>
    </>
  )
}
